package com.example.icedcap.topeka_fake.model.quiz;

import android.os.Parcel;

import java.util.Arrays;

/**
 * Created by doushuqi on 15-7-15下午9:48.
 * Email:doushuqi0409@gmail.com
 */
public abstract class OptionQuiz<T> extends Quiz<int[]> {
    private T[] mOptions;

    public OptionQuiz(String question, int[] answer, T[] options, boolean solved) {
        super(question, answer, solved);
        mOptions = options;
    }

    protected OptionQuiz(Parcel in) {
        super(in);
    }

    public T[] getOptions() {
        return mOptions;
    }

    public void setOptions(T[] options) {
        mOptions = options;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeIntArray(getAnswer());
    }


    @Override
    public boolean isAnswerCorrect(int[] answer) {
        return Arrays.equals(getAnswer(), answer);
    }



    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = result * 31 + Arrays.hashCode(mOptions);
        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof OptionQuiz)) {
            return false;
        }
        OptionQuiz that = (OptionQuiz) o;
        if (!(Arrays.equals(getAnswer(), (int[])that.getAnswer()))) {
            return false;
        }

        if (!(Arrays.equals(mOptions, that.mOptions))) {
            return false;
        }
        return true;
    }
}
